@import (reference) 'mixins';

.box {
  .fluid-prop(padding-left, @grid-offset-box-sm, @size-sm-min, @grid-offset-box-md, @size-sm-max);
  .fluid-prop(padding-left, @grid-offset-box-md, @size-lg-min, @grid-offset-box-xl, @size-lg-max);
  .fluid-prop(padding-right, @grid-offset-box-sm, @size-sm-min, @grid-offset-box-md, @size-sm-max);
  .fluid-prop(padding-right, @grid-offset-box-md, @size-lg-min, @grid-offset-box-xl, @size-lg-max);

  margin-left: auto;
  margin-right: auto;
  max-width: @grid-width;
  padding-left: @grid-offset-box-md;
  padding-right: @grid-offset-box-md;
  width: 100%;

  @media @xs-max {
    padding-left: @grid-offset-box-sm;
    padding-right: @grid-offset-box-sm;
  }

  @media @xl-min {
    padding-left: @grid-offset-box-xl;
    padding-right: @grid-offset-box-xl;
  }

  &__row {
    .fluid-prop-sm(margin-left, -@grid-offset-sm, -@grid-offset-md);
    .fluid-prop-sm(margin-right, -@grid-offset-sm, -@grid-offset-md);

    display: flex;
    flex-wrap: wrap;

    &_no-offset {
      margin: 0;
    }
  }

  &__col {
    .fluid-prop-sm(padding-left, @grid-offset-sm, @grid-offset-md);
    .fluid-prop-sm(padding-right, @grid-offset-sm, @grid-offset-md);

    .col-make(xs, @xs-min);
    .col-make(sm, @sm-min);
    .col-make(md, @md-min);
    .col-make(lg, @lg-min);
    .col-make(xl, @xl-min);

    flex-basis: 0;
    flex-grow: 1;
    max-width: 100%;
    position: relative;
    transition: flex-basis @animation, max-width @animation;

    &_no-offset {
      padding: 0;
    }
  }
}

.col-make(@class, @query) {
  .col-loop(@grid-columns, @class, @query);

  &_@{class}_auto {
    @media @query {
      flex-basis: auto;
      max-width: none;
    }
  }
}

.col-loop(@index, @class, @query) when (@index >= 0) {
  .col-loop((@index - 1), @class, @query);

  &_@{class}_@{index} {
    @media @query {
      flex-basis: percentage(@index / @grid-columns);
      max-width: percentage(@index / @grid-columns);
    }
  }

  &_left_@{class}_@{index} {
    transition: flex-basis @animation, left @animation, max-width @animation;

    @media @query {
      left: percentage(@index / @grid-columns);
    }
  }

  &_right_@{class}_@{index} {
    transition: flex-basis @animation, max-width @animation, right @animation;

    @media @query {
      right: percentage(@index / @grid-columns);
    }
  }
}
